package com.community.pojo.entity;

import lombok.Data;

@Data
public class LayuiResult<T> {
    private Integer code;  // 状态码 0表示成功
    private String msg;   // 消息
    private Long count;   // 总条数
    private T data;       // 数据列表

    public static <T> LayuiResult<T> build(Long total, T data) {
        LayuiResult<T> result = new LayuiResult<>();
        result.setCode(0);
        result.setMsg("查询成功");
        result.setCount(total);
        result.setData(data);
        return result;
    }

    public static <T> LayuiResult<T> error(String message) {
        LayuiResult<T> result = new LayuiResult<>();
        result.setCode(1);
        result.setMsg(message);
        result.setCount(0L);
        result.setData(null);
        return result;
    }
}